package cn.wendellup.bootStrap.valueobject.entity;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import cn.wendellup.bootStrap.valueobject.constants.FileUsedType;

public class FileInfo implements Serializable, RowMapper<FileInfo> {

    private static final long serialVersionUID = 1309826557171883448L;

    public static class FieldStatus {
        public static int appId = 1 << 0;
        public static int uId = 1 << 1;
        public static int fileName = 1 << 2;
        public static int fileUsedType = 1 << 3;
        public static int saveName = 1 << 4;
        public static int fileSize = 1 << 5;
        public static int isSave = 1 << 6;
        public static int isDelete = 1 << 7;
        public static int isComplete = 1 << 8;
        public static int imageType = 1 << 9;
        public static int md5 = 1 << 10;
    }

    private int updateStatus = 0;
    
    private long efsId = 0;
    private int appId = 0;
    private long uId = 0;
    private String fileName;
    private FileUsedType fileUsedType;
    private String imageType;
    private String saveName;
    private long fileSize = 0;
    private boolean isSave = false;
    private boolean isDelete = false;
    private boolean isComplete = false;
    private long createTime = 0;
    private String md5;


    public long getEFSId() {
        return efsId;
    }

    public void setEFSId(long efsId) {
        this.efsId = efsId;
    }

    public int getAppId() {
        return appId;
    }

    public void setAppId(int appId) {
        if (this.appId != appId) {
            this.appId = appId;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.appId;
        }
    }

    public long getUId() {
        return uId;
    }

    public void setUId(long uId) {
        if (this.uId != uId) {
            this.uId = uId;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.uId;
        }
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        if (this.fileName != fileName) {
            this.fileName = fileName;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.fileName;
        }
    }

    public FileUsedType getFileUsedType() {
        return fileUsedType;
    }

    public void setFileUsedType(FileUsedType fileUsedType) {
        if (this.fileUsedType != fileUsedType) {
            this.fileUsedType = fileUsedType;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.fileUsedType;
        }
    }

    public String getSaveName() {
        return saveName;
    }

    public void setSaveName(String saveName) {
        if (this.saveName != saveName) {
            this.saveName = saveName;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.saveName;
        }
    }

    public long getFileSize() {
        return fileSize;
    }

    public void setFileSize(long fileSize) {
        if (this.fileSize != fileSize) {
            this.fileSize = fileSize;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.fileSize;
        }
    }

    public boolean isSave() {
        return isSave;
    }

    public void setSave(boolean isSave) {
        if (this.isSave != isSave) {
            this.isSave = isSave;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.isSave;
        }
    }

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean isDelete) {
        if (this.isDelete != isDelete) {
            this.isDelete = isDelete;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.isDelete;
        }
    }

    public boolean isComplete() {
        return isComplete;
    }

    public void setComplete(boolean isComplete) {
        if (this.isComplete != isComplete) {
            this.isComplete = isComplete;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.isComplete;
        }
    }

    public String getImageType() {
        return imageType;
    }

    public void setImageType(String imageType) {
        if (this.imageType != imageType) {
            this.imageType = imageType;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.imageType;
        }
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getMd5() {
        return md5;
    }

    public void setMd5(String md5) {
        if (this.md5 != md5) {
            this.md5 = md5;
            this.updateStatus = this.updateStatus | FileInfo.FieldStatus.md5;
        }
    }

    public int getUpdateStatus() {
        return updateStatus;
    }

    public void setUpdateStatus(int updateStatus) {
        this.updateStatus = updateStatus;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("FileInfo [updateStatus=");
        builder.append(updateStatus);
        builder.append(", efsId=");
        builder.append(efsId);
        builder.append(", appId=");
        builder.append(appId);
        builder.append(", uId=");
        builder.append(uId);
        builder.append(", fileName=");
        builder.append(fileName);
        builder.append(", fileUsedType=");
        builder.append(fileUsedType);
        builder.append(", saveName=");
        builder.append(saveName);
        builder.append(", imageType=");
        builder.append(imageType);
        builder.append(", fileSize=");
        builder.append(fileSize);
        builder.append(", isSave=");
        builder.append(isSave);
        builder.append(", isDelete=");
        builder.append(isDelete);
        builder.append(", isComplete=");
        builder.append(isComplete);
        builder.append(", createTime=");
        builder.append(createTime);
        builder.append(", md5=");
        builder.append(md5);
        builder.append("]");
        return builder.toString();
    }

	@Override
	public FileInfo mapRow(ResultSet rs, int arg1) throws SQLException {
		FileInfo entity = new FileInfo();
		int i=1;
		entity.setEFSId(rs.getLong(i++));
		entity.setAppId(rs.getInt(i++));
		entity.setUId(rs.getLong(i++));
		entity.setFileName(rs.getString(i++));
		entity.setFileUsedType(FileUsedType.lookup(rs.getInt(i++)));
		entity.setImageType(rs.getString(i++));
		entity.setFileSize(rs.getLong(i++));
		entity.setSaveName(rs.getString(i++));
		entity.setSave(rs.getBoolean(i++));
		entity.setDelete(rs.getBoolean(i++));
		entity.setComplete(rs.getBoolean(i++));
		entity.setCreateTime(rs.getLong(i++));
		entity.setMd5(rs.getString(i++));
		return entity;
	}

}
